// 最近表示包括当前  过去表示不包括当前
export const dateShortcutKeyJS = {
  data() {
    return {
      choiceDate: '',
      pickerOptions: {
        shortcuts: [
          {
            text: '今天',
            onClick: (picker) => {
              const start = new Date();
              picker.$emit('pick', [start, start]);
            }
          },
          {
            text: '昨天',
            onClick: (picker) => {
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
              picker.$emit('pick', [start, start]);
            }
          },
          {
            text: '最近3天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 2);
              picker.$emit('pick', [date, new Date()]);
            }
          },
          {
            text: '本周', // 从周一算起
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              const days =
                new Date().getDay() == 0 ? 6 : new Date().getDay() - 1;
              start.setTime(start.getTime() - 3600 * 1000 * 24 * days);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '最近7天',
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 6);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '最近30天',
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 29);
              picker.$emit('pick', [start, end]);
            }
          }
        ],
        onPick: ({ maxDate, minDate }) => {
          this.choiceDate = minDate.getTime();
          if (maxDate) {
            this.choiceDate = '';
          }
        },
        // 限制手动选择时间不能超过31天
        disabledDate: (time) => {
          if (this.choiceDate) {
            const one = 30 * 24 * 3600 * 1000;
            const minTime = this.choiceDate - one;
            const maxTime = this.choiceDate + one;
            return time.getTime() < minTime || time.getTime() > maxTime;
          }
          return time.getTime() > Date.now();
        }
      },
      pickerOptions2: {
        shortcuts: [
          {
            text: '今天',
            onClick: (picker) => {
              const start = new Date();
              picker.$emit('pick', [start, start]);
            }
          },
          {
            text: '昨天',
            onClick: (picker) => {
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
              picker.$emit('pick', [start, start]);
            }
          },
          {
            text: '本周', // 从周一算起
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              const days =
                new Date().getDay() == 0 ? 6 : new Date().getDay() - 1;
              start.setTime(start.getTime() - 3600 * 1000 * 24 * days);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '本月',
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              const days = new Date().getDate() - 1;
              start.setTime(start.getTime() - 3600 * 1000 * 24 * days);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '过去7天', // 过去7天 不包括今天 共7天
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              end.setTime(end.getTime() - 3600 * 1000 * 24 * 1);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '过去30天', // 过去30天 不包括今天 共30天
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              end.setTime(end.getTime() - 3600 * 1000 * 24 * 1);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '过去6周', // 过去6个完整周 不包括本周
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              const days = new Date().getDay() == 0 ? 7 : new Date().getDay();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * (days + 41));
              end.setTime(end.getTime() - 3600 * 1000 * 24 * days);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '过去6个月', // 前6月  不包括本月
            onClick: (picker) => {
              const start = new Date(
                new Date().getFullYear(),
                new Date().getMonth() - 6,
                1,
              );
              const days = new Date(
                new Date().getFullYear(),
                new Date().getMonth(),
                0,
              ).getDate();
              const end = new Date(
                new Date().getFullYear(),
                new Date().getMonth() - 1,
                days,
              );
              picker.$emit('pick', [start, end]);
            }
          }
        ],
        onPick: ({ maxDate, minDate }) => {
          this.choiceDate = minDate.getTime();
          if (maxDate) {
            this.choiceDate = '';
          }
        },
        // 限制手动选择时间不能超过31天
        disabledDate: (time) => {
          if (this.choiceDate) {
            const one = 30 * 24 * 3600 * 1000;
            const minTime = this.choiceDate - one;
            const maxTime = this.choiceDate + one;
            return time.getTime() < minTime || time.getTime() > maxTime;
          }
          return time.getTime() > Date.now();
        }
      },
      pickerOptions3: {
        shortcuts: [
          {
            text: '昨天',
            onClick: (picker) => {
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
              picker.$emit('pick', [start, start]);
            }
          },
          {
            text: '本周', // 从周一算起
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              const days =
                new Date().getDay() == 0 ? 6 : new Date().getDay() - 1;
              start.setTime(start.getTime() - 3600 * 1000 * 24 * days);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '本月',
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              const days = new Date().getDate() - 1;
              start.setTime(start.getTime() - 3600 * 1000 * 24 * days);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '过去7天', // 过去7天 不包括今天 共7天
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              end.setTime(end.getTime() - 3600 * 1000 * 24 * 1);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '过去30天', // 过去30天 不包括今天 共30天
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              end.setTime(end.getTime() - 3600 * 1000 * 24 * 1);
              picker.$emit('pick', [start, end]);
            }
          }
        ],
        onPick: ({ maxDate, minDate }) => {
          this.choiceDate = minDate.getTime();
          if (maxDate) {
            this.choiceDate = '';
          }
        },
        // 限制手动选择时间不能超过31天
        disabledDate: (time) => {
          if (this.choiceDate) {
            const one = 30 * 24 * 3600 * 1000;
            const minTime = this.choiceDate - one;
            const maxTime = this.choiceDate + one;
            return time.getTime() < minTime || time.getTime() > maxTime;
          }
          return time.getTime() > Date.now();
        }
      },
      sortStrategyArrayA: [], // A组排序推荐全部策略
      sortStrategyArrayB: [], // B组排序推荐全部策略
      sortStrategyArrayC: [], // c组排序推荐全部策略
      sortStrategyArrayD: [], // D组排序推荐全部策略
      dataNameMap: {},
      dataNameMap2: {}
    };
  },

  methods: {
    arrayFilter(type = 1) {
      if (type === 1) {
        this.dataNameMap = {};

        if (this.listQuery1.sortStrategyName1 == 'all') {
          const arr1 = this.sortStrategyArrayA;
          arr1.forEach((item) => {
            const name = `A-${item}`;
            this.dataNameMap[name] = [];
          });
        } else {
          this.dataNameMap['A-line'] = [];
        }

        if (this.listQuery1.sortStrategyName2 == 'all') {
          const arr1 = this.sortStrategyArrayB;
          arr1.forEach((item) => {
            const name = `B-${item}`;
            this.dataNameMap[name] = [];
          });
        } else {
          this.dataNameMap['B-line'] = [];
        }
      } else {
        this.dataNameMap2 = {};

        if (this.listQuery2.sortStrategyName1 == 'all') {
          const arr1 = this.sortStrategyArrayC;
          arr1.forEach((item) => {
            const name = `A-${item}`;
            this.dataNameMap2[name] = [];
          });
        } else {
          this.dataNameMap2['A-line'] = [];
        }

        if (this.listQuery2.sortStrategyName2 == 'all') {
          const arr1 = this.sortStrategyArrayD;
          arr1.forEach((item) => {
            const name = `B-${item}`;
            this.dataNameMap2[name] = [];
          });
        } else {
          this.dataNameMap2['B-line'] = [];
        }
      }
    },

    getLegendAndseries(objName, type) {
      const obj = type == 2 ? this.dataNameMap2 : this.dataNameMap;

      const legend = [];
      const series = [];
      Object.keys(obj).forEach((key) => {
        const item = {
          name: key,
          type: 'line',
          data: objName[key]
        };
        legend.push(key);
        series.push(item);
      });
      return { legend, series };
    }
  }
};
